package com.boot.jdk8;

import com.turo.pushy.apns.ApnsClient;
import com.turo.pushy.apns.ApnsClientBuilder;
import com.turo.pushy.apns.auth.ApnsSigningKey;
import com.turo.pushy.apns.util.SimpleApnsPushNotification;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;

import java.io.File;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class RestTemplateTester {

    private static final RestTemplate restTemplate = new RestTemplate();

    @Test
    public void doGet() {
        ApnsClient apnsClientBuilder=null;
        try {
             apnsClientBuilder = new ApnsClientBuilder()
                    .setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST).setSigningKey(ApnsSigningKey
                            .loadFromPkcs8File(new File("d:/autohome-test.p8"),"R33482C953","BF62B78KBG")).build();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        }
        apnsClientBuilder.close();
        String res = restTemplate.getForObject("http://www.baidu.com", String.class);
        System.out.println(res);
        String sendkey = "sendkey_new1_%s_%s_%s_%s";
        //String.format(sendkey, biztype, contenttype, bizid, linkurl)
        String key = String.format(sendkey, 10, 0, -1, "aHR0cHM6Ly9zdmRzLmFwcC5hdXRvaG9tZS5jb20uY24vcS5waHA/cWlkPTU5MiZ0eXBlPTMmZmxhZz1wbS5keW5hbWljXzU5Ml8xXzIwMTkwODAxXzExMzEwMA==");
        System.out.println(key);

    }

    public void doPost() {

    }
}
